package com.jiazhong.basic.shuxin.net;

import lombok.SneakyThrows;

import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class DemoD1 {

    @SneakyThrows
    public static void main(String[] args) {
        ServerSocket serverSocket = new ServerSocket(8889);
        Socket socket = serverSocket.accept();
        OutputStream outputStream = socket.getOutputStream();
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.print("Input:");
            String message = scanner.next();
            outputStream.write(message.getBytes(StandardCharsets.UTF_8));
            if ("bye".equals(message)) {
                break;
            }
        }

    }
}
